<?php

	#doc
	#	classname:	Qmain_firmController
	#	scope:		PUBLIC
	#
	#/doc
	
	class Qmain_firmController extends CController
	{
		public $layout = "admin";
		public $image;
		public function actionList ()
		{
			$firm=main_firm::model()->findALL();
			$this->render('application.views.qmain_firm.list',array('firm'=>$firm));
		}
		
		public function actionAdd ()
		{
			$this->render('application.views.qmain_firm.add');
		}
			
			public function actionSave ()
			{
				
				if (( isset($_POST['title']))&&( isset($_POST['area2'])) )
				{
					$main_firm=new main_firm();
					$main_firm->name=$_POST['title'];
						$main_firm->text=$_POST['area2'];
							$main_firm->main_flag=$_POST['flag'];
						
						$image = CUploadedFile::getInstance($main_firm,'image');
						
						if($image != null)
						{      
						 $image->saveAs("images/firm/".$image);   
						}	
						$main_firm->image=$image;
						$main_firm->save();
				}
			}
			public function actionUpdate ()
			{
				if ((isset($_POST['id']))&&(isset($_POST['title']))&&(isset($_POST['area2'])))
				{
					$main_firm=main_firm::model()->findByPk($_POST['id']);
					$main_firm->name=$_POST['title'];
					$main_firm->text=$_POST['area2'];
					$main_firm->main_flag=$_POST['flag'];
					$image = CUploadedFile::getInstance($main_firm,'image');
					if($image != null)
					{      
						$image->saveAs("images/firm/".$image);   
					}
					$main_firm->image=$image;
					//Обновляем запись
					if ( $main_firm->save() )
					{
						$this->redirect(array('adminka/qmain_firm/list'));
					}
					else{}
				}
			}
			
			public function actionEdit ()
			{
				
					$id=$_GET['id'];										
					$firm=main_firm::model()->findByPk($id);;
					$this->render('application.views.qmain_firm.edit',array("firm"=>$firm));
					
			}
	
	}
	###

?>